package kr.hkit.androidcomplete03.ch20;

import kr.hkit.androidcomplete03.R;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class FragmentEx extends Activity {
	final static String TAG = "Fragment Life Cyle";

	protected void onCreate(Bundle savedInstanceState) {
		Log.d(TAG, "Activity - onCreate()");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fragmentex);
	}

	protected void onStart() {
		Log.d(TAG, "Activity - onStart()");
		super.onStart();
	}

	protected void onResume() {
		Log.d(TAG, "Activity - onResume()");
		super.onResume();
	}

	protected void onPause() {
		Log.d(TAG, "Activity - onPause()");
		super.onPause();
	}

	protected void onStop() {
		Log.d(TAG, "Activity - onStop()");
		super.onStop();
	}

	protected void onDestroy() {
		Log.d(TAG, "Activity - onDestroy()");
		super.onDestroy();
	}

	public static class CounterFragment extends Fragment {
		
		public void onCreate(Bundle savedInstanceState) {
			Log.d(TAG, "		Fragment - onCreate()");
			super.onCreate(savedInstanceState);
		}
		
		public void onAttach(Activity activity) {
			Log.d(TAG, "		Fragment - onAttach()");
			super.onAttach(activity);
		}

		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			Log.d(TAG, "		Fragment - onCreateView()");
			View root = inflater.inflate(R.layout.ch20_counterfragment,
					container, false);
			Button btnIncrease = (Button) root
					.findViewById(R.id.ch20_btnincrease);
			final TextView textCounter = (TextView) root
					.findViewById(R.id.ch20_txtcounter);
			btnIncrease.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					int count = Integer.parseInt(textCounter.getText()
							.toString());
					textCounter.setText(Integer.toString(count + 1));
				}
			});
			return root;
		}

		public void onActivityCreated(Bundle savedInstanceState) {
			Log.d(TAG, "		Fragment - onActivityCreated()");
			super.onActivityCreated(savedInstanceState);
		}

		public void onStart() {
			Log.d(TAG, "		Fragment - onStart()");
			super.onStart();
		}

		public void onResume() {
			Log.d(TAG, "		Fragment - onResume()");
			super.onResume();
		}

		public void onPause() {
			Log.d(TAG, "		Fragment - onPause()");
			super.onPause();
		}

		public void onStop() {
			Log.d(TAG, "		Fragment - onStop()");
			super.onStop();
		}

		public void onDestroyView() {
			Log.d(TAG, "		Fragment-onDestroyView()");
			super.onDestroyView();
		}

		public void onDestroy() {
			Log.d(TAG, "		Fragment - onDestroy()");
			super.onDestroy();
		}

		public void onDetach() {
			Log.d(TAG, "		Fragment - onDetach()");
			super.onDetach();
		}
	}
}
